﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace 企业人事管理系统
{
    public partial class loginForm : Form
    {
        private Form mainF;
        public loginForm()
        {
            ImageChangeForm.initResDir();
            InitializeComponent();
        }

        private void LOGINbutton1_Click(object sender, EventArgs e)
        {
            string name = LOGINtextBox1.Text.Trim();
            string passWord = LOGINtextBox2.Text.Trim();

            string loginSql = string.Format(
                "select {1} from {0} where {1}='{3}' and {2}='{4}'",
                DataName.userTable, //0
                DataName.userName,  //1
                DataName.userPassword,  //2
                name, //3
                passWord  //4
                );

            try
            {
                OledbOP.initConnect(DataName.testConStr);
                OleDbDataReader re =  OledbOP.getReader(loginSql);
                re.Read();
                if(re.HasRows)
                {
                    name = re.GetString(0);
                }
                else
                {
                    name = null;
                }
            }catch(Exception ex)
            {
                name = null;
                MessageBox.Show(ex.ToString());
            }

            if (name != null)
            {
                mainF = new mainForm(name,this);
                mainF.Show();
                clearInput();
            }
            else
            {
                MessageBox.Show("用户名密码错误！");
                LOGINtextBox2.Text = "";
            }
        }

        private void loginForm_Load(object sender, EventArgs e)
        {
            LOGINtextBox2.Text = "";
        }

        public void clearInput()
        {
            LOGINtextBox1.Text = "";
            LOGINtextBox2.Text = "";
        }
    }
}
